/*
 * 
 * 
 * 
 */
package com.hboxs.asl.controller.admin;

import com.hboxs.asl.Message;
import com.hboxs.asl.Pageable;
import com.hboxs.asl.entity.PointTrade;
import com.hboxs.asl.service.PointTradeService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
import javax.servlet.http.HttpSession;

import javax.annotation.Resource;

/**
 * Controller - 积分记录
 */
@Controller("adminPointTradeController")
@RequestMapping("/asl-admin/point_trade")
public class PointTradeController extends BaseController {

    @Resource(name = "pointTradeServiceImpl")
    private PointTradeService pointTradeService;

    /**
     * 添加
     */
    @RequestMapping(value = "/add", method = RequestMethod.GET)
    public String add(ModelMap model, HttpSession session) {
        return "/admin/point_trade/add";
    }

    /**
     * 保存
     */
    @RequestMapping(value = "/save", method = RequestMethod.POST)
    public String save(PointTrade pointTrade, RedirectAttributes redirectAttributes) {
        if (!isValid(pointTrade)) {
            return ERROR_VIEW;
        }
        pointTradeService.save(pointTrade);
        addFlashMessage(redirectAttributes, SUCCESS_MESSAGE);
        return "redirect:list.htm";
    }

    /**
     * 编辑
     */
    @RequestMapping(value = "/edit", method = RequestMethod.GET)
    public String edit(Long id, ModelMap model, HttpSession session) {
        model.addAttribute("pointTrade", pointTradeService.find(id));
        return "/admin/point_trade/edit";
    }

    /**
     * 更新
     */
    @RequestMapping(value = "/update", method = RequestMethod.POST)
    public String update(PointTrade pointTrade, RedirectAttributes redirectAttributes) {
        if (!isValid(pointTrade)) {
            return ERROR_VIEW;
        }
        pointTradeService.update(pointTrade, "");
        addFlashMessage(redirectAttributes, SUCCESS_MESSAGE);
        return "redirect:list.htm";
    }

    /**
     * 列表
     */
    @RequestMapping(value = "/list", method = RequestMethod.GET)
    public String list(Pageable pageable, ModelMap model) {
        model.addAttribute("page", pointTradeService.findPage(pageable));
        return "/admin/point_trade/list";
    }

    /**
     * 删除
     */
    @RequestMapping(value = "/delete", method = RequestMethod.POST)
    public
    @ResponseBody
    Message delete(Long[] ids) {
        pointTradeService.delete(ids);
        return SUCCESS_MESSAGE;
    }

}
